package com.cykj.enterprise.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.cykj.common.utils.EmailValidateUtil;
import com.cykj.common.utils.SaTokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @BelongsProject: smart_recruit_backend
 * @BelongsPackage: com.cykj.enterprise.controller
 * @Author: 蔡张君逸
 * @CreateTime: 2025-08-16 14:13
 * @Description: TODO
 * @Version: 1.0
 */
@CrossOrigin
@RestController
@RequestMapping("test")
public class TestToken {
    @Autowired
    EmailValidateUtil emailValidateUtil;
    @RequestMapping("login")
    public String login() {
//        登录    admin是扩展属性role的值 id就是loginId
        return SaTokenUtils.saLogin("user", 10080);
    }
    @RequestMapping("check")
    public void check() {
//        是否登录
        System.out.println(StpUtil.isLogin());
            StpUtil.logout();
        System.err.println(StpUtil.isLogin());
    }
    @RequestMapping("getInfo")
    public void getInfo() {
        
//        拿扩展属性
        HashMap<String, Object> map = SaTokenUtils.saGetInfo();
        String role = (String) map.get("role");
        
//        拿发送者角色id
        int id = StpUtil.getLoginIdAsInt();

        //  拿token
        String token = StpUtil.getTokenValue();

        System.out.println("id:"+id+"role:"+role+"token:"+token);
    }
    @RequestMapping("sendEmail")
    public void sendEmail() throws Exception {
        emailValidateUtil.send("2435615220@qq.com","测试","测试标题");
    }
}